<?php

namespace App\Dao\Order;

use Yj\Daos\BaseDaos;
use App\Model\Order\OtherOrder;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;
use Hyperf\Utils\Collection;

/**
 * @var OtherOrder
 * @method $this params($params)
 */
class OtherOrderDao extends BaseDaos
{
    public function searchParams(Collection $params)
    {
            $search = $this->getSearch();
            $params->check('id',function($id) use ($search) {
                $search->where('id',$id);
            });
            return $search;
    }

    public function lists(Collection $params)
    {
            $data = $this->params($params)->orderByDesc("id")->getList();
            return $data;
    }

    public function add(Collection $params)
    {
            $data = $this->create($params->toArray());
            return $data;
    }

    public function edit(int $id, Collection $params)
    {
            $data = $this->params(_Collect(["id"=>$id]))->firstOrError();
            $data->fill($params->toArray());
            return $data->save();
    }

    public function read(int $id)
    {
           $data = $this->params(_Collect(["id"=>$id]))->firstOrError();
           return $data;
    }

    public function del(int $id)
    {
            $data = $this->params(_Collect(["id"=>$id]))->firstOrError();
            return $data->delete();
    }
}
